package mest.controller.hws;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import mest.entity.plan_workfinish;
import mest.service.hws.plan_workfinishService;
import mest.service.system.DBService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/Plan_WorkFinishController")
@CrossOrigin
public class Plan_WorkFinishController {

    @Resource
    private plan_workfinishService plan_workfinishService;
    @Autowired
    private DBService dbService;

    @RequestMapping("/insertModel")
    public String insert(@RequestBody JSONObject json) {
        String theirDb = dbService.getDbName();
        Map<String, Object> record = json.toJavaObject(Map.class);
        record.put("theirDb", theirDb);
        return plan_workfinishService.insert(record);
    }

    @RequestMapping("/selectAll")
    public Map<String, Object> selectAll(Integer limit, Integer page, Integer finishStatus) {
        String theirDb = dbService.getDbName();
        return plan_workfinishService.selectAll(theirDb, limit, page, finishStatus);
    }

    @RequestMapping("/selectById")
    public String selectById(Integer finishStatus) {
        String theirDb = dbService.getDbName();
        return plan_workfinishService.selectById(theirDb, finishStatus);
    }

    @RequestMapping("/updateByone")
    public String updateByone(plan_workfinish record) {
        String theirDb = dbService.getDbName();
        return plan_workfinishService.updateByone(theirDb, record);
    }

}
